package com.qf.service.impl;

import com.qf.dao.GoodsDao;
import com.qf.dao.impl.GoodsDaoImpl;
import com.qf.domain.Goods;
import com.qf.domain.GoodsType;
import com.qf.domain.PageBean;
import com.qf.service.GoodsService;
import com.qf.service.GoodsTypeService;

import java.util.List;

/**
 * @author YDW
 * projectName:shopping
 * time:2022/4/19 19:11
 * description:
 */
public class GoodsServiceImpl implements GoodsService {
    GoodsDao goodsDao=new GoodsDaoImpl();

    @Override
    public PageBean findByPage(int typeId, int pageNum, int pageSize) {
        Long totalCount=goodsDao.findTotalCount(typeId);
        List<Goods> data=goodsDao.findData(typeId,(pageNum-1)*pageSize,pageSize);
        PageBean pageBean=new PageBean(pageNum,totalCount,pageSize,data);
        return pageBean;
    }

    @Override
    public Goods findGoodsById(int id) {
        Goods goods= goodsDao.findGoodsById(id);
        //查询商品分类信息，存储到商品对象中
        GoodsTypeService typeService=new GoodsTypeServiceImpl();
        //根据商品分类id，查询分类消息
        GoodsType goodsType=typeService.findById(goods.getTypeid());
        //存储到商品对象中
        goods.setGoodsType(goodsType);
        return goods;
    }

    @Override
    public List<Goods> findAllGoods() {
        return goodsDao.selectAll();
    }

    @Override
    public void AddGoods(Goods goods) {
        goodsDao.insertGoods(goods);
    }
}
